package com.liu.netty5.client;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.codec.LineBasedFrameDecoder;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;
import org.apache.commons.lang3.CharSetUtils;

import java.nio.charset.Charset;
import java.util.Scanner;

/**
 * Created by Administrator on 2019/9/2 0002.
 */
public class ClientNetty {

    public static void main(String[] args) throws InterruptedException {




        Bootstrap bootstrap = new Bootstrap();

        bootstrap.group(new NioEventLoopGroup());
        bootstrap.channel(NioSocketChannel.class);

        bootstrap.handler(new ChannelInitializer<Channel>() {
            @Override
            protected void initChannel(Channel channel) throws Exception {
                channel.pipeline().addLast(new LineBasedFrameDecoder(1048576));

                channel.pipeline().addLast(new StringEncoder(Charset.forName("UTF-8")));
                channel.pipeline().addLast(new StringDecoder(Charset.forName("UTF-8")));
                channel.pipeline().addLast(new ClientHandler1());


            }
        });
        ChannelFuture futrue = bootstrap.connect("localhost", 81).sync();
        futrue.channel().closeFuture().sync();


    }




}
